unit fmCardSumByMon;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev,
  dxPSCompsProvider, dxPSFillPatterns, dxPSEdgePatterns, dxPSPDFExportCore,
  dxPSPDFExport, cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon,
  dxPScxEditorProducers, dxPScxExtEditorProducers,
  dxPScxPageControlProducer, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk,
  StdCtrls, Buttons, Mask, ComCtrls, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses,
  cxGridCustomView, cxGrid, MemDS, DBAccess, MSAccess, cxDBLookupComboBox;

type
  TCardSumByMonForm = class(TForm)
    grp1: TGroupBox;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    dtpBegin: TDateTimePicker;
    dtpEnd: TDateTimePicker;
    medtAccount: TMaskEdit;
    btnOK: TBitBtn;
    btnExport: TBitBtn;
    btnPrint: TBitBtn;
    dxComponentPrinter: TdxComponentPrinter;
    msspCardSum: TMSStoredProc;
    tvAccount: TcxGridDBTableView;
    glAccount: TcxGridLevel;
    cxGrid1: TcxGrid;
    srcAccount: TDataSource;
    tvAccountPayCardNo: TcxGridDBColumn;
    tvAccountFYear: TcxGridDBColumn;
    tvAccountFMonth: TcxGridDBColumn;
    tvAccountRealMoney: TcxGridDBColumn;
    dxComponentPrinterLink1: TdxGridReportLink;
    tblAccount: TMSTable;
    srcCardSum: TDataSource;
    tvAccountAccountNo: TcxGridDBColumn;
    procedure btnOKClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  CardSumByMonForm: TCardSumByMonForm;

implementation

uses
  fmMain;

{$R *.dfm}

procedure TCardSumByMonForm.btnOKClick(Sender: TObject);
Var
   vAccountNo: String;
   vBeginDate, vEndDate: TDate;
begin
  if Trim(medtAccount.Text) = '' then
     vAccountNo := '0'
  else
     vAccountNo := Trim(medtAccount.Text);

  btnOK.Enabled := False;
  vBeginDate := dtpBegin.Date;
  vEndDate   := dtpEnd.Date;

  msspCardSum.Close;
  msspCardSum.ParamByName('BeginDate').AsDate := vBeginDate;
  msspCardSum.ParamByName('EndDate').AsDate   := vEndDate;
  msspCardSum.ParamByName('AccountNo').AsString := vAccountNo;
  msspCardSum.Open;
  tvAccount.DataController.Groups.FullExpand;
  btnOK.Enabled := True;
end;

procedure TCardSumByMonForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   msspCardSum.Close;
   tblAccount.Close;
   Action := caFree;
end;

procedure TCardSumByMonForm.FormCreate(Sender: TObject);
begin
   tblAccount.Open;
   dtpEnd.Date   := Date;
  dtpbegin.Date := Date - 30;
end;

procedure TCardSumByMonForm.btnPrintClick(Sender: TObject);
begin
   dxComponentPrinter.Preview(True);
end;

end.
